<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>27. 嵌套分组与不记录组</title>
    </head>
    <body>

    </body>
    <script>
        /*
         * 
         **/
        //  let hd = `
        // https://www.houdunren.com
        //  `;
        // let reg = /https:\/\/\w+\.\w+\.(com|org|cn)/gi;
        // let res = hd.match(reg)
        // console.log(res) //["https://www.houdunren.com"]

        //  let hd = `
        // https://www.houdunren.com
        //  `;
        //  //?: 后面的那原子组不保留，即所谓的不记录组
        // let reg = /https:\/\/(\w+\.\w+\.(?:com|org|cn))/i;
        // let res = hd.match(reg)
        // console.dir(res) //["https://www.houdunren.com"]
   
   let hd = `
   https://www.houdunren.com
   http://houdunwang.com
   https://hdcms.com
    `;
    //?: 后面的那原子组不保留，即所谓的不记录组
   let reg = /https?:\/\/((?:\w+\.)?\w+\.(?:com|org|cn))/gi;
   console.dir(reg.exec(hd))
   console.dir(reg.lastIndex)
   console.dir(reg.exec(hd))
   console.dir(reg.lastIndex)
   console.dir(reg.exec(hd))
   console.dir(reg.lastIndex)
   console.dir(reg.exec(hd))
   console.dir(reg.lastIndex)
   let urls=[];
   while((res=reg.exec(hd))){
       urls.push(res[1])
   }
   console.log(urls) //["www.houdunren.com", "houdunwang.com", "hdcms.com"]
    </script>
</html>
